<?php
class ViewAction extends Action{
	public function homework(){
		$hw_id = $_GET['hw_id'];
		$homeworkinfo_dao = M('homeworkinfo');
		$condition['id'] = $hw_id;
		$homeworkinfo_result = $homeworkinfo_dao->where($condition)->find();
		
		$student_dao = M('student');
		$student_condition;
		$student_condition['id'] = $_SESSION['id'];
		$student_result = $student_dao->where($student_condition)->find();
		
		$group_id = $student_result['group_id'];
		$group_condition;
		$group_condition['group_id'] = $group_id;
		$members = $student_dao->where($group_condition)->select();
		
		
		$stuhomework_dao = M('stuhomework');
		$members_hw;
		foreach ($members as $key => $member) {
			$stuhomework_condition;
		    $stuhomework_condition['hw_id'] = $hw_id;
		    $stuhomework_condition['stu_id'] = $member['id'];
			$members_hw[] = $stuhomework_dao->where($stuhomework_condition)->find();
			$members_hw[$key]['name'] = $member['name'];
		}
		$this->assign('homework', $homeworkinfo_result);
		$this->assign('memembers', $members);
		$this->assign('members_hw', $members_hw);
		$this->display();
	}
    
}
?>